import { resolve } from "path";
import { UserConfig, loadEnv } from "vite";
import { createVitePlugins } from "./build/vite";
import { root, env } from "./build/env";

// 路径查找
function pathResolve(dir: string) {
    return resolve(root, ".", dir);
}

export default (): UserConfig => {
    return {
        root,
        server: {
            open: env.VITE_OPEN === "true"
        },
        // 项目使用的 vite 插件
        plugins: createVitePlugins(),
        resolve: {
            extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".scss", ".css"],
            alias: [
                {
                    find: /@\//,
                    replacement: `${pathResolve("src")}/`
                }
            ]
        }
    };
};
